package com.atguigu.srb.core.controller.api;


import com.atguigu.common.result.R;
import com.atguigu.common.utils.JwtUtils;
import com.atguigu.srb.core.pojo.entity.BorrowInfo;
import com.atguigu.srb.core.service.BorrowInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-09-13
 */
@RestController
@RequestMapping("/api/core/borrowInfo")
public class ApiBorrowInfoController {

    @Resource
    BorrowInfoService borrowInfoService;
    @GetMapping("/getBorrowInfoStatusByUserId")
    public R getBorrowInfoStatusByUserId(HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
      Integer borrowInfoStatus =
              borrowInfoService.getBorrowInfoStatusByUserId(userId);
        return R.ok().data("borrowInfoStatus",borrowInfoStatus);
    }
    @PostMapping("/auth/save")
    public R saveBorrowerInfo(@RequestBody BorrowInfo borrowInfo,HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        borrowInfoService.saveBorrowerInfo(borrowInfo,userId);
        return R.ok();
    }

}

